package com.viroyal.monitorlib.network;

import com.viroyal.monitorlib.entity.HBbean;
import com.viroyal.monitorlib.entity.OssAttributesResponse;
import com.viroyal.monitorlib.entity.UploadRes;
import com.viroyal.monitorlib.entity.rx.UpdateRes;
import com.viroyal.monitorlib.network.req.AppsResponse;
import com.viroyal.monitorlib.network.req.VersionRequest;
import com.viroyal.monitorlib.network.rsp.ApiResponse;
import com.viroyal.monitorlib.network.rsp.BaseResponse;
import com.viroyal.monitorlib.network.rsp.DeviceSecretResponse;
import com.viroyal.monitorlib.network.rsp.FileUploadResponse;
import com.viroyal.monitorlib.network.rsp.MacRequest;
import com.viroyal.monitorlib.network.rsp.VersionResponse;

import okhttp3.MultipartBody;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
import rx.Observable;

/**
 * Created by cxy_nj on 2016/12/27.
 */

public interface UpdateApi {
    @POST("about/upgrade")
    Observable<VersionResponse> getVersionMsg(@Header("school_id") String school_id, @Header(
            "app_id") String appId,
                                              @Header("master_key") String masterKey,
                                              @Body VersionRequest versionRequest);

    /**
     * 获取app信息
     *
     * @return
     */
    @GET("v1/smartclass/apps")
    Observable<AppsResponse> getApps(@Header("school_id") String school_id);

    @Multipart
    @POST("upload")
    Observable<FileUploadResponse> uploadFile(@Header("school_id") String school_id, @Header(
            "dev_mac") String dev_mac, @Part("usage") String sign, @Part MultipartBody.Part file);

    /**
     * 获取app信息
     *
     * @return
     */
    @POST("device/devmonitor/dev/reg")
    Observable<DeviceSecretResponse> getDeviceSecret(@Header("school_id") String school_id,
                                                     @Header("dev_mac") String dev_mac, @Body MacRequest macRequest);

    /**
     *上报已安装的app
     */
    @POST("device/devmonitor/dev/{mac}/installed")
    Observable<BaseResponse> getInstalled(@Header("school_id") String school_id, @Header("dev_mac") String dev_mac, @Path("mac") String mac, @Body HBbean installedRequest);


    /**
     * 上报设备前台app
     */
    @POST("device/devmonitor/dev/{mac}/top_app")
    Observable<BaseResponse> getTopAppList(@Header("school_id") String school_id, @Header("dev_mac") String dev_mac, @Path("mac") String mac, @Body HBbean topRequest);

    /**
     * 获取阿里云oss相关
     */
    @GET
    Observable<OssAttributesResponse> getOssInfo(@Url String url, @Header("master_key") String master_key, @Header("school_id") String school_id);

    /**
     *上报已安装的app
     */
    @POST("device/devmonitor/dev/{mac}/install-progress")
    Observable<BaseResponse> installProgress(@Header("school_id") String school_id, @Header("dev_mac") String dev_mac, @Path("mac") String mac, @Body UpdateRes installedRequest);

    /**
     * 上报安装的应用不在前台报警
     * @param req
     * @return
     */
    @POST("device/devmonitor/top-error")
    Observable<BaseResponse> reportTopError(@Header("school_id") String school_id, @Header("dev_mac") String dev_mac, @Body UploadRes req);

    /**
     * 上报异常log
     * @param req
     * @return
     */
    @POST("device/devmonitor/logs/upload")
    Observable<BaseResponse> reportCrash(@Header("school_id") String school_id, @Header("dev_mac") String dev_mac, @Body UploadRes req);

    /**
     * 获取api
     * @param mac
     * @param app_name
     * @return
     */
    @GET("device/devmonitor/dev/api-config")
    Observable<ApiResponse> api(@Header("dev_mac") String mac,@Header("school_id") String school_id, @Query("app_name") String app_name);
}
